<?php
    $this->headTitle('Duyệt Tin Miễn Phí','append');    
    switch(strlen($this->userCheck['mobile'])) {        
    case 10:
        $this->userCheck['mobile'] = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2 $3", $this->userCheck['mobile']);
        break;
    case 11:
        $this->userCheck['mobile'] = preg_replace("/([0-9]{4})([0-9]{4})([0-9]{3})/", "$1 $2 $3", $this->userCheck['mobile']);
        break;
    default:        
        break;
    }
    switch(strlen($this->proCheck['mobile'])) {        
    case 10:
        $this->proCheck['mobile'] = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2 $3", $this->proCheck['mobile']);
        break;
    case 11:
        $this->proCheck['mobile'] = preg_replace("/([0-9]{4})([0-9]{4})([0-9]{3})/", "$1 $2 $3", $this->proCheck['mobile']);
        break;
    default:        
        break;
    }
    
    $start = new DateTime(date("Y-m-d H:i:s",$this->proCheck['startDate']));
    $end = new DateTime(date("Y-m-d H:i:s",$this->proCheck['endDate']));
//    $start->setTime(date("H"),date("i"));
//    $end = new DateTime($form->getValue('endDate'));
//    $end->setTime(date("H"),date("i"));                                                                                                                
    //$days= ((int)$end->diff($start)->days+1)*$price['price'];
    $days= ((int)$end->diff($start)->days+1);    
    //pr($days);    
?>
<form id="form" class="form-option" method="post" action="" enctype="multipart/form-data" name="form">
<div class="dashboard-menu dashboard-admin">
    <span class="back">&nbsp;</span>
    <a href="<?=$this->url(array('module'=>'admin', 'controller'=>'product', 'action'=>'editvip', 'id'=>$this->proCheck['id']))?>"><h1>Duyệt tin VIP</h1></a>    
    <button id="submitbutton" type="submit" class="btn btn-primary" style="margin-right: 10px;">Duyệt</button>
    <a href="/admin/product/deletevip/id/<?php echo $this->proCheck['id'];?>" onclick="return confirm('Bạn có muốn xóa tin này?');"><button type="button" class="btn btn-danger">Xóa</button></a>
</div>

<div class="row">
    <div class="col-md-12">
    
        <div class="widget-big product-detail">            
            <h2 class="jumbotron text-center"><input type="text" value="<?php echo $this->proCheck['title'];?>" name="title" style="width:80%"/></h2>                        
            <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                <!-- Indicators -->
                <ol class="carousel-indicators">
                    <?php                         
                        $image = json_decode($this->proCheck['photo']);
                        $i=0;
                        foreach($image as $ime){
                            if($i==0){
                                echo '<li data-target="#carousel-example-generic" data-slide-to="'.$i.'" class="active"></li>';
                            }else{
                                echo '<li data-target="#carousel-example-generic" data-slide-to="'.$i.'"></li>';
                            }   
                            $i++;                                                     
                        }
                        $configTran= new Zend_Config_Ini(CONFIG_PATH.'/transaction.ini', APPLICATION_ENV);
                        $tranL=$configTran->transaction->toArray();
                        $configHu= new Zend_Config_Ini(CONFIG_PATH.'/human.ini', APPLICATION_ENV);
                        $tranH=$configHu->human->toArray();
                        $this->proCheck['transaction'] = $tranL[$this->proCheck['transaction']];                         
                        $this->proCheck['human'] = $tranH[$this->proCheck['human']];                        
                    ?>                    
                </ol>        
                <!-- Wrapper for slides -->
                <div class="carousel-inner" role="listbox">
                <?php
                    $i=0;
                    foreach($image as $ime){
                       if($i==0){
                ?>
                    <div class="item active">
                        <img src="<?=$ime?>" onerror="this.onerror=null;this.src='public/static/images/noimage.jpg';"/>
                        <div class="carousel-caption"></div>
                    </div>
                <?php
                       }else{
                ?>
                    <div class="item">
                        <img src="<?=$ime?>" onerror="this.onerror=null;this.src='public/static/images/noimage.jpg';"/>
                        <div class="carousel-caption">                        
                        </div>
                    </div>
                <?php
                       }
                       $i++; 
                    }
                ?>                                                     
                </div>        
                <!-- Controls -->
                <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>
            <hr />       
            <div class="row">                            
                <div class="col-md-3">
                    <h4>Chi tiết sản phẩm</h4>
                    <div class="info-group">
                        <label class="group-label">ID: </label>
                        <span class="group-element"><?=$this->proCheck['id']?></span>
                    </div>                    
                    <div class="info-group">
                        <label class="group-label">Khu vực: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['areaName']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Danh mục: </label>
                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['catName']?> &gt;&gt; <?=$this->proCheck['itemName']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Giao dịch: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['transaction']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Đối tượng: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['human']?></span>
                    </div>                                        
                </div>    
                <div class="col-md-6">
                    <h4>Mô tả sản phẩm</h4>                
                    <div class="info-group">
                        <span class="group-element"><textarea name="content" rows="5" cols="70"><?php echo $this->proCheck['content'];?></textarea></span>
                    </div>
                    <center><h4>Giá sản phẩm</h4></center>
                    <div class="info-group">                        
                        <center><span class="group-element" style="color:red;font-size:15px;font-weight:bold;"><?php echo number_format($this->proCheck['price'],0,'.',',')?> VNĐ</span></center>
                    </div>
                </div>
                <div class="col-md-3">
                    <h4>Thông tin liên hệ</h4>
                    <div class="info-group">
                        <label class="group-label">Người liên hệ: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['contact']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Số di động: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['mobile']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Email: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['emailCont']?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Địa chỉ liên hệ: </label>                        
                    </div>
                    <div class="info-group text-right">                        
                        <span class="group-element"><?=$this->proCheck['addressCont']?></span>
                    </div>
                </div>
            </div>
            <hr />
            <div class="row" style="margin-bottom: 30px;">                                            
                <div class="col-md-6">
                    <center><h4>Chi tiết tin rao vặt</h4></center>            
                    <div class="info-group">
                        <label class="group-label">Ngày tạo: </label>
                        <span class="group-element"><?php echo date('Y-m-d H:i',$this->proCheck['createDate']);?></span>
                    </div>                        
                    <div class="info-group">
                        <label class="group-label">Ngày bắt đầu: </label>
                        <span class="group-element">
                        <input type="text" name="startDate" class="datepicker2" value="<?php echo date("Y-m-d H:i",$this->proCheck['startDate']);?>" placeholder="dd/mm/yy"/>
                        </span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Ngày kết thúc: </label>
                         <span class="group-element">
                         <input type="text" name="endDate" class="datepicker2" value="<?php echo date("Y-m-d H:i",$this->proCheck['endDate']);?>" placeholder="dd/mm/yy"/>
                         </span>
                    </div>   
                    <div class="info-group">
                        <label class="group-label priceAd-label">Phí đăng: </label>
                        <span class="group-element priceAd-element"><?php echo number_format($this->proCheck['priceAd'],0,'.',',');?> VNĐ &lt;=&gt; <?php echo $days?> ngày đăng tin</span>
                    </div>                     
                    <div class="info-group">
                        <label class="group-label estimate-label">Ước tính: </label>
                        <span class="group-element estimate-element"><?php echo date("Y-m-d H:i",time())?> đến <?php echo date("Y-m-d H:i",time()+($days*86400))?></span>
                        <a id="estimate" title="Sử dụng kết quả ước tính"><span style="cursor:pointer;color:green" class="glyphicon glyphicon-ok"></span></a>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Loại tin: </label>
                        <span class="group-element"><?php echo ($this->proCheck['type']=='no')? 'Tin Thường':'Tin Vip'?></span>
                    </div>              
                    <div class="info-group">
                        <label class="group-label">Tài khoản sở hữu: </label>
                        <span class="group-element"><?php echo $this->proCheck['email']?></span>
                    </div>
                </div>
                <div class="col-md-6">
                    <center><h4>Thông tin tài khoản</h4></center>
                    <div class="info-group">
                        <label class="group-label">Tên chủ tài khoản: </label>
                        <span class="group-element"><?php echo $this->userCheck['fullname'] ?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Di động: </label>
                        <span class="group-element"><?php echo $this->userCheck['mobile'] ?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Tên đăng nhập: </label>
                        <span class="group-element"><?php echo $this->userCheck['username'] ?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Địa chỉ: </label>
                        <span class="group-element"><?php echo $this->userCheck['address'] ?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Email: </label>
                        <span class="group-element"><?php echo $this->userCheck['email'] ?></span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Số dư: </label>
                        <span class="group-element"><?php echo number_format($this->userCheck['gold'],0,'.',',') ?> VNĐ</span>
                    </div>
                    <div class="info-group">
                        <label class="group-label">Số bài đã đăng: </label>
                        <span class="group-element"><?php echo $this->userCheck['qty'] ?></span>
                    </div>
                </div>
                            
               
            </div>                                                                                            
        </div>
    </form>
    </div>
</div>

<script type="text/javascript">
    function daydiff(first, second) {
    	return (second-first)/(1000*60*60*24)		
	}    
    $('a#estimate').click(function(){
        $('input[name=startDate]').val('<?php echo date("Y-m-d H:i",time())?>');
        $('input[name=endDate]').val('<?php echo date("Y-m-d H:i",time()+($days*86400))?>');
        $('span.priceAd-element').attr('style','color:green;font-weight:bold');        
    });  
    $('input[name=startDate]').change(function(){        
        var start = $("input[type=text][name=startDate]").val();                         
        var end = $("input[type=text][name=endDate]").val();
        var tempDate = start.split(" ");var startD = tempDate[0].split("-");var startT = tempDate[1].split(":"); 
        var tempDate = end.split(" ");var endD = tempDate[0].split("-");var endT = tempDate[1].split(":");                                     
        var start = new Date((startD[0]) , (startD[1]-1), (startD[2]),(startT[0]),(startT[1]));
        var end = new Date((endD[0]) , (endD[1]-1), (endD[2]),(endT[0]),(endT[1]));
        var numDate = daydiff(start,end);
        if(numDate < <?php echo $days ?>){
            $('span.priceAd-element').attr('style','color:red;font-weight:bold');            
        }else{
            if(numDate > <?php echo $days ?>){
                $('span.priceAd-element').attr('style','color:orange;font-weight:bold');
            }else{
                $('span.priceAd-element').attr('style','color:green;font-weight:bold');    
            }                          
        }                
    });
    $('input[name=endDate]').change(function(){        
        var start = $("input[type=text][name=startDate]").val();                         
        var end = $("input[type=text][name=endDate]").val();
        var tempDate = start.split(" ");var startD = tempDate[0].split("-");var startT = tempDate[1].split(":"); 
        var tempDate = end.split(" ");var endD = tempDate[0].split("-");var endT = tempDate[1].split(":");                                     
        var start = new Date((startD[0]) , (startD[1]-1), (startD[2]),(startT[0]),(startT[1]));
        var end = new Date((endD[0]) , (endD[1]-1), (endD[2]),(endT[0]),(endT[1]));
        var numDate = daydiff(start,end);
        if(numDate < <?php echo $days ?>){
            $('span.priceAd-element').attr('style','color:red;font-weight:bold');          
        }else{            
            if(numDate > <?php echo $days ?>){
                $('span.priceAd-element').attr('style','color:orange;font-weight:bold');
            }else{
                $('span.priceAd-element').attr('style','color:green;font-weight:bold');    
            }  
        }
    });
    $('button#submitbutton').click(function(){
        var start = $("input[type=text][name=startDate]").val();                         
        var end = $("input[type=text][name=endDate]").val();
        var tempDate = start.split(" ");var startD = tempDate[0].split("-");var startT = tempDate[1].split(":"); 
        var tempDate = end.split(" ");var endD = tempDate[0].split("-");var endT = tempDate[1].split(":");                                     
        var start = new Date((startD[0]) , (startD[1]-1), (startD[2]),(startT[0]),(startT[1]));
        var end = new Date((endD[0]) , (endD[1]-1), (endD[2]),(endT[0]),(endT[1]));
        var numDate = daydiff(start,end);
        if(numDate < <?php echo $days ?>){
            alert('Số ngày đăng không đủ yêu cầu của khách hàng!');
            return false;
        }else{
            return true;
        }                                                                                                                           
    });
</script>